<?php
namespace bee;

define("BEE_RADIO_HORIZONTAL", 1);
define("BEE_RADIO_VERTICAL", 2);

/**
 *
 * @author dzelenika
 * @todo nije ništa implementirano, samo je prekopiran kod klase radio
 *
 */
class radioGroup extends widget
{
  public $values;
  public $labels;
  public $radios;
  public $orientation;

  private $events = array(	"onBlurFn", "onClickFn", "onDblClickFn",
  							"onKeyDownFn", "onKeyPressFn", "onKeyUpFn",
                            "onMouseDownFn", "onMouseMoveFn", "onMouseOutFn", "onMouseOverFn", "onMouseUpFn");

  function __construct($name, &$bindValue = "", array $options = array())
  { parent::__construct($name);
  //die("*" . $bindValue . "*");
    $this->value = &$bindValue;
    $this->labels = isset($options["labels"]) ? $options["labels"] : array();
    $this->values = isset($options["values"]) ? $options["values"] : array();

    $this->radios = array();
    foreach ($this->values as &$rVal)
    { $nr = new radio($name, $this->value, $rVal, $name . "_" . $rVal);
      //$nr->drawMe = false;
      //echo ":: $name, $this->value, $rVal, $name _ $rVal";
      $this->radios[] = $nr;
    }
  }

 /**
  * @param array $evt
  */
  public function onDraw($evt)
  { foreach($this->radios as &$rVal)
    { foreach ($this->events as $evt)
      { if($this->$evt)
        { $rVal->$evt = clone $this->$evt;
        }
      }
      $rVal->checked();
    }
    $this->fillDSDoc();
  }

  public function setArrayLV($array, $append = false)
  {
    if(!$append)
    { $this->labels = array();
      $this->values = array();
    }
    foreach ($array as $key => &$value)
    {$this->labels[] = $value;
      $this->values[] = $key;

      $nr = new radio($this->name, $this->value, $key, $this->name . "_" . $key);
      $nr->drawMe = false;
      $this->radios[] = $nr;
    }

  }

 /**
  * @param string $fillVar
  */
  public function fillDSDoc($fillVar = "")
  {
    $__DSDoc = XMLDataHub::getInstance();
    if($fillVar)
    { $__DSDoc->setVariable($fillVar, $this->value);
    }
    $__DSDoc->setObject("widgets/" . $this->name, $this);
  }
}
